<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-radio-group
      v-model="form.type"
      style="margin-bottom: 30px"
      size="mini"
      @change="onChange"
    >
      <el-radio-button label="1">普通单张开票</el-radio-button>
      <el-radio-button label="2">多订单合一开票</el-radio-button>
    </el-radio-group>
    <el-form
      ref="form"
      size="mini"
      :model="form"
      label-position="top"
      class="myform"
    >
      <div>
        <el-form-item label="店铺:" class="myform-item">
          <el-select
            v-model="form.sellerid"
            placeholder="请选择开具发票的店铺"
            clearable
          >
            <el-option
              v-for="item in shoplist"
              :key="item.sellerid"
              :label="item.sellertitle"
              :value="item.sellerid"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单号:" class="myform-item">
          <el-input
            v-model="form.sourceidarr"
            placeholder="多订单请用 , 隔开"
            @keyup.enter.native="onSearch"
            clearable
            style="width: 400px"
          ></el-input>
        </el-form-item>
        <el-form-item label="买家昵称:" class="myform-item">
          <el-input
            v-model="form.buyername"
            placeholder="请输入买家昵称"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="抬头|税号:" class="myform-item">
          <el-input
            v-model="form.title"
            placeholder="请输入抬头或税号"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="任务状态:" class="myform-item">
          <el-select
            v-model="form.status"
            placeholder="请选择任务状态"
            clearable
          >
            <el-option
              v-for="item in statuslist"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开票日期:" class="myform-item">
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="form.strdate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item style="margin: 36px 10px 0">
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button type="primary" @click="onUpdatelist">更新</el-button>
        </el-form-item>
        <el-form-item style="margin-top: 36px" v-if="form.type == 1">
          <el-button type="primary" @click="onMerge"
            >申请多订单合一开票</el-button
          >
          <!-- <el-button type="primary" @click="onAdd">新增面料</el-button> -->
        </el-form-item>
      </div>
    </el-form>

    <div style="margin: 10px 0">
      <div style="font-size: 14px; display: flex">
        后台开票状态：<el-checkbox-group
          v-model="form.invoicing_statusarr"
          @change="onChangeCheckboxGroup"
        >
          <el-checkbox
            v-for="item in cities"
            :key="item.invoicing_status"
            :label="item.value"
            >{{ item.label }}</el-checkbox
          >
        </el-checkbox-group>
      </div>
    </div>
    <div style="margin-bottom: 10px" v-if="form.type == 2">
      <el-button plain type="danger" size="mini" @click="onMergeDD(2)">发起冲红申请</el-button>
      <el-button plain type="primary" size="mini" @click="onMergeDD(1)">修改开票信息</el-button>
      <el-button plain type="warning" size="mini" @click="onMergeDD(3)">取消多合一开票</el-button>
      <el-button plain size="mini" @click="onMergeDD(4)">再次申请开票</el-button>
    </div>
    <el-table v-if="is" ref="multipleTable" :data="tableData" style="width: 100%" :height="browserHeight - 310" border size="mini">
      <!-- <el-table-column type="selection" width="55" fixed> </el-table-column> -->
      <el-table-column
        label="订单号"
        align="center"
        prop="sourceid"
        width="170"
        fixed
      >
      </el-table-column>
      <el-table-column
        label="订单状态"
        align="center"
        prop="order_status"
        width="100"
      >
      </el-table-column>
      <el-table-column
        label="任务状态"
        align="center"
        prop="status"
        width="100"
      >
        <template slot-scope="{ row }">
          <div
            :style="{
              color:
                row.status == 1
                  ? '#67C23A'
                  : row.status == 2
                  ? '#E6A23C'
                  : row.status == 0
                  ? '#F56C6C'
                  : '',
            }"
          >
            {{
              row.status == 1
                ? "已完成"
                : row.status == 0
                ? "待处理"
                : row.status == 2
                ? "处理中"
                : row.status == 3
                ? "暂停中"
                : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="是否需开票"
        align="center"
        prop="hongchong_status"
        width="100"
      >
        <template slot-scope="{ row }">
          <div
            :style="{
              color: row.hongchong_status == 1 ? '#999999' : '',
            }"
          >
            {{
              row.hongchong_status == 1
                ? "无需开票"
                : row.hongchong_status == 2
                ? "需开票"
                : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="后台发票状态"
        align="center"
        prop="invoicing_status"
        width="100"
      >
        <template slot-scope="{ row }">
          <el-popover
            trigger="hover"
            placement="top"
            v-if="row.invoicing_status == 2"
          >
            <p>{{ row.err_msg }}</p>
            <div slot="reference" class="name-wrapper">
              <div
                :style="{
                  color:
                    row.invoicing_status == 1
                      ? '#67C23A'
                      : row.invoicing_status == 2
                      ? '#F56C6C'
                      : row.invoicing_status == 3
                      ? '#E6A23C'
                      : row.invoicing_status == 4
                      ? '#2c70d6'
                      : '',
                }"
              >
                {{
                  row.invoicing_status == 1
                    ? "已开票"
                    : row.invoicing_status == 2
                    ? "开票失败"
                    : row.invoicing_status == 3
                    ? "申请冲红"
                    : row.invoicing_status == 4
                    ? "冲红成功"
                    : row.invoicing_status == 5
                    ? "冲红失败"
                    : row.invoicing_status == 0
                    ? "未开票"
                    : ""
                }}
              </div>
            </div>
          </el-popover>
          <div
            v-else
            :style="{
              color:
                row.invoicing_status == 1
                  ? '#67C23A'
                  : row.invoicing_status == 2
                  ? '#F56C6C'
                  : row.invoicing_status == 3
                  ? '#E6A23C'
                  : row.invoicing_status == 4
                  ? '#2c70d6'
                  : '',
            }"
          >
            {{
              row.invoicing_status == 1
                ? "已开票"
                : row.invoicing_status == 2
                ? "开票失败"
                : row.invoicing_status == 3
                ? "申请冲红"
                : row.invoicing_status == 4
                ? "冲红成功"
                : row.invoicing_status == 5
                ? "冲红失败"
                : row.invoicing_status == 0
                ? "未开票"
                : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="发票类型"
        align="center"
        prop="invoice_headerid"
        width="80"
      >
        <template slot-scope="{ row }">
          {{ row.invoice_headerid == 900 ? "个人" : "公司" }}
        </template>
      </el-table-column>
      <el-table-column
        label="多订单合一标识码"
        align="center"
        prop="merge_tag"
        width="80"
        v-if="form.type == 2"
      >
      </el-table-column>
      <el-table-column label="开票信息" align="center">
        <el-table-column label="抬头/税号" align="center" width="250">
          <template slot-scope="{ row }">
            {{ row.invoice_header || "--" }} /
            {{ row.invoicing_number || "--" }}
          </template>
        </el-table-column>
        <el-table-column label="地址/电话" align="center" width="250">
          <template slot-scope="{ row }">
            {{ row.opening_bank_address || "--" }} /
            {{ row.opening_bank_tel || "--" }}
          </template>
        </el-table-column>
        <el-table-column label="开户行/账号" align="center" width="250">
          <template slot-scope="{ row }">
            {{ row.opening_bank || "--" }} /
            {{ row.opening_bank_number || "--" }}
          </template>
        </el-table-column>
        <el-table-column
          label="客服备注"
          align="center"
          prop="notes"
          width="100"
        >
        </el-table-column>
      </el-table-column>
      <el-table-column label="电子邮箱" align="center" prop="email" width="160">
      </el-table-column>
      <el-table-column label="店铺" align="center" prop="sellerid" width="140">
        <template slot-scope="{ row }">
          {{ row.sellerid | shopfilters() }}
        </template>
      </el-table-column>
      <el-table-column label="买家昵称" align="center" prop="buyername">
      </el-table-column>
      <el-table-column label="实付金额" align="center" prop="pay_amount">
      </el-table-column>
      <el-table-column label="开票商品" align="center" width="1000">
        <template slot-scope="{ row }">
          <el-table border :data="row.order_detail" size="mini">
            <el-table-column
              label="子订单号"
              align="center"
              width="180"
              prop="son_order_no"
            >
            </el-table-column>
            <el-table-column
              label="商品标题"
              align="center"
              prop="product_name"
            >
            </el-table-column>
            <el-table-column label="购买数量" align="center" prop="num">
            </el-table-column>
            <el-table-column
              label="子订单号实付金额"
              align="center"
              prop="pay_amount"
            >
            </el-table-column>
            <el-table-column label="货品编号" align="center" prop="sku_code">
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column
        label="创建人"
        align="center"
        prop="adduserid"
        width="100"
      >
      </el-table-column>
      <el-table-column
        label="执行人"
        align="center"
        prop="douserid"
        width="100"
      >
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="addtime"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="修改时间"
        align="center"
        prop="updatetime"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="开票时间"
        align="center"
        prop="kai_createtime"
        width="160"
      >
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="220">
        <template slot-scope="{ row }">
          <div v-if="form.type == 1">
            <el-button type="text" size="default" @click="onDetail(row.sourceid)">详情</el-button>
            <el-button type="text" size="default"
              v-if="row.hongchong_status == 2 &&(row.invoicing_status == 3 || row.invoicing_status == 5)" @click="onUpdateinfo(row, 1)">
                新开票信息</el-button>
            <el-button type="text" size="default"
              v-if="row.hongchong_status == 2 &&(row.invoicing_status == 0 ||row.invoicing_status == 2 ||row.invoicing_status == 4)"
                       @click="onUpdateinfo(row, 2)">修改信息</el-button>
            <el-button type="text" size="default" v-if="row.hongchong_status == 1 && row.invoicing_status == 4"
              @click="onUpdateinfo(row, 3)">再次申请开票</el-button>
            <el-button type="text" size="default" v-if="row.hongchong_status == 2 && row.invoicing_status == 1"
              @click="onChongHong(row)">发起冲红申请</el-button>

            <el-button type="text" size="default"
              v-if="row.invoiceserialnum &&row.invoicing_status != 0 &&row.invoicing_status != 2"
              @click="downloadInvoice(row.invoiceserialnum)">下载发票</el-button>
          </div>
          <div v-else>
            <el-button type="text" size="default" @click="onDetail(row.sourceid)">详情</el-button>
            <el-button type="text" size="default"
              v-if="row.hongchong_status == 2 &&(row.invoicing_status == 3 || row.invoicing_status == 5)"
              @click="onUpdateinfo(row, 1)">新开票信息</el-button>
            <el-button type="text" size="default"
              v-if="row.invoiceserialnum &&row.invoicing_status != 0 &&row.invoicing_status != 2"
              @click="downloadInvoice(row.invoiceserialnum)">下载发票</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminBanNiuGetInvoiceList_all"
    />

    <el-dialog title="下载发票" :visible.sync="dialogVisible" :before-close="handleClose">
      <div>
        <img
          src="../../../assets/images/login.png"
          alt=""
          style="width: 900px"
        />
      </div>
      <div class="dialogimgdiv" style="display: flex; justify-content: center">
        <div style="width: 200px; height: 150px; border: 5px solid #ccc">
          <img
            src="../../../assets/images/login.png"
            alt=""
            style="width: 100%; height: 100%"
          />
        </div>
        <div style="width: 200px; height: 150px; border: 5px solid #ccc">
          <img
            src="../../../assets/images/login.png"
            alt=""
            style="width: 100%; height: 100%"
          />
        </div>
        <div style="width: 200px; height: 150px; border: 5px solid #ccc">
          <img
            src="../../../assets/images/1.png"
            alt=""
            style="width: 100%; height: 100%"
          />
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >下 载</el-button
        >
      </span>
    </el-dialog>
    <el-dialog :title=" islook == 1? '新开票信息': islook == 2? '修改信息': islook == 3? '再次申请开票': ''" :visible.sync="dialogVisibleupdate"
      :before-close="handleClose"
      width="900px"
    >
      <div>
        <el-radio
          v-model="info.invoice_headerid"
          label="900"
          :disabled="islook == 1"
          >个人电子发票</el-radio
        >
        <el-radio
          v-model="info.invoice_headerid"
          label="18661"
          :disabled="islook == 1"
          >公司电子发票</el-radio
        >
      </div>
      <div class="dialogOrderUpdate" v-if="info.invoice_headerid == 900">
        <div>
          <div>订单号:</div>
          {{ info.sourceid }}
        </div>
        <div>
          <div>店铺:</div>
          {{ info.sellerid | shopfilters() }}
        </div>
        <div class="star">
          <div>抬头:</div>
          <el-input
            size="mini"
            v-model="info.invoice_header"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div class="star">
          <div>邮箱:</div>
          <el-input
            size="mini"
            v-model="info.email"
            :disabled="islook == 1"
          ></el-input>
        </div>
      </div>
      <div class="dialogOrderUpdate" v-if="info.invoice_headerid == 18661">
        <div>
          <div>订单号:</div>
          {{ info.sourceid }}
        </div>
        <div>
          <div>店铺:</div>
          {{ info.sellerid | shopfilters() }}
        </div>
        <div class="star">
          <div>抬头:</div>
          <el-input
            size="mini"
            v-model="info.invoice_header"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div class="star">
          <div>邮箱:</div>
          <el-input
            size="mini"
            v-model="info.email"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div class="star">
          <div>税号:</div>
          <el-input
            size="mini"
            v-model="info.invoicing_number"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div>
          <div>开户行:</div>
          <el-input
            size="mini"
            v-model="info.opening_bank"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div>
          <div>开户行号:</div>
          <el-input
            size="mini"
            v-model="info.opening_bank_number"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div>
          <div>地址:</div>
          <el-input
            size="mini"
            v-model="info.opening_bank_address"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div>
          <div>电话:</div>
          <el-input
            size="mini"
            v-model="info.opening_bank_tel"
            :disabled="islook == 1"
          ></el-input>
        </div>
      </div>
      <div style="display: flex; align-items: center">
        客服备注:<el-input
          size="mini"
          style="width: 720px; margin-left: 10px; margin-top: 10px"
          v-model="info.notes"
          :disabled="islook == 1"
        ></el-input>
      </div>
      <div style="margin-top: 10px">
        <div>开票商品</div>
        <el-table border :data="info.order_detail" size="mini">
          <el-table-column
            label="子订单号"
            align="center"
            width="180"
            prop="son_order_no"
          >
          </el-table-column>
          <el-table-column label="商品标题" align="center" prop="product_name">
          </el-table-column>
          <el-table-column label="购买数量" align="center" prop="num">
          </el-table-column>
          <el-table-column
            label="子订单号实付金额"
            align="center"
            prop="pay_amount"
          >
            <template slot-scope="{ row }">
              <el-input
                v-model="row.pay_amount"
                placeholder=""
                size="mini"
                v-if="islook != 1"
              ></el-input>
              <div v-else>{{ row.pay_amount }}</div>
            </template>
          </el-table-column>
          <el-table-column label="货品编号" align="center" prop="sku_code">
          </el-table-column>
        </el-table>
        <div style="text-align: right; color: red; font-weight: 800">
          合计：{{ numt }}
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">取 消</el-button>
        <el-button
          type="primary"
          size="mini"
          @click="onUpdateInvoicing"
          v-if="islook != 1"
          >确 认</el-button
        >
      </span>
    </el-dialog>
    <el-dialog title="申请多订单合一开票" :visible.sync="dialogVisibleupdateD" :before-close="handleClose" width="900px">
      <div v-if="step == 1">
        <dialogD
          @onMultipleSelection="onMultipleSelection"
          v-if="dialogVisibleupdateD && step == 1"
        ></dialogD>
        <div slot="footer" class="dialog-footer" style="margin-top: 10px">
          <el-button
            @click="handleStep"
            type="primary"
            size="mini"
            :disabled="multipleSelection.length < 2"
            >下一步</el-button
          >
        </div>
      </div>
      <div v-else>
        <div>
          <el-radio
            v-model="infoD.invoice_headerid"
            label="900"
            :disabled="islook == 1"
            >个人电子发票</el-radio
          >
          <el-radio
            v-model="infoD.invoice_headerid"
            label="18661"
            :disabled="islook == 1"
            >公司电子发票</el-radio
          >
        </div>
        <div class="dialogOrderUpdate" v-if="infoD.invoice_headerid == 900">
          <div style="width: 900px">
            <div>订单号:</div>
            <span style="color: #2c70d6; width: 900px">
              {{ infoD.sourceidarr.join(",") }}
            </span>
          </div>
          <div class="star">
            <div>抬头:</div>
            <el-input
              size="mini"
              v-model="infoD.invoice_header"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div class="star">
            <div>邮箱:</div>
            <el-input
              size="mini"
              v-model="infoD.email"
              :disabled="islook == 1"
            ></el-input>
          </div>
        </div>
        <div class="dialogOrderUpdate" v-if="infoD.invoice_headerid == 18661">
          <div style="width: 900px">
            <div>订单号:</div>
            <span style="color: #2c70d6; width: 900px">
              {{ infoD.sourceidarr.join(",") }}
            </span>
          </div>
          <div class="star">
            <div>抬头:</div>
            <el-input
              size="mini"
              v-model="infoD.invoice_header"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div class="star">
            <div>邮箱:</div>
            <el-input
              size="mini"
              v-model="infoD.email"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div class="star">
            <div>税号:</div>
            <el-input
              size="mini"
              v-model="infoD.invoicing_number"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>开户行:</div>
            <el-input
              size="mini"
              v-model="infoD.opening_bank"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>开户行号:</div>
            <el-input
              size="mini"
              v-model="infoD.opening_bank_number"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>地址:</div>
            <el-input
              size="mini"
              v-model="infoD.opening_bank_address"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>电话:</div>
            <el-input
              size="mini"
              v-model="infoD.opening_bank_tel"
              :disabled="islook == 1"
            ></el-input>
          </div>
        </div>
        <div style="display: flex; align-items: center">
          客服备注:<el-input
            size="mini"
            style="width: 720px; margin-left: 10px; margin-top: 10px"
            v-model="infoD.notes"
            :disabled="islook == 1"
          ></el-input>
        </div>
        <div style="margin-top: 10px">
          <div>开票商品</div>
          <el-table border :data="infoD.order_detail" size="mini" height="400">
            <el-table-column
              label="子订单号"
              align="center"
              width="180"
              prop="son_order_no"
            >
            </el-table-column>
            <el-table-column
              label="商品标题"
              align="center"
              prop="product_name"
            >
            </el-table-column>
            <el-table-column label="购买数量" align="center" prop="num">
            </el-table-column>
            <el-table-column
              label="子订单号实付金额"
              align="center"
              prop="pay_amount"
            >
              <template slot-scope="{ row }">
                <el-input
                  v-model="row.pay_amount"
                  placeholder=""
                  size="mini"
                  v-if="islook != 1"
                ></el-input>
                <div v-else>{{ row.pay_amount }}</div>
              </template>
            </el-table-column>
            <el-table-column label="货品编号" align="center" prop="sku_code">
            </el-table-column>
          </el-table>
          <div style="text-align: right; color: red; font-weight: 800">
            合计：{{ numD }}
          </div>
        </div>
        <span slot="footer" class="dialog-footer" style="text-align: right">
          <el-button @click="handleClose" size="mini">取 消</el-button>
          <el-button
            type="primary"
            size="mini"
            @click="onUpdateInvoicingD"
            v-if="islook != 1"
            >确 认</el-button
          >
        </span>
      </div>
    </el-dialog>
    <el-dialog title="发起冲红申请" :visible.sync="dialogVisibleupdateC" :before-close="handleClose" width="900px">
      <div>
        <el-radio v-model="hongchong_status" label="1">只冲红不开票</el-radio>
        <el-radio v-model="hongchong_status" label="2">冲红再开票</el-radio>
      </div>
      <div
        class="dialogOrderUpdate"
        v-if="dialogVisibleupdateC && hongchong_status == 1"
        style="margin: 10px 0"
      >
        <div>
          <div style="text-align: left">订单号:</div>
          {{ info.sourceid }}
        </div>
        <div>
          <div>店铺:</div>
          {{ info.sellerid | shopfilters() }}
        </div>
      </div>
      <div v-if="hongchong_status == 2" style="margin-top: 10px">
        <div>
          <el-radio-group
            v-model="info.invoice_headerid"
            style="margin-bottom: 30px"
            size="mini"
          >
            <el-radio label="900">个人电子发票</el-radio>
            <el-radio label="18661">公司电子发票</el-radio>
          </el-radio-group>
        </div>
        <div class="dialogOrderUpdate" v-if="info.invoice_headerid == 900">
          <div style="width: 900px">
            <div>订单号:</div>
            <span style="color: #2c70d6; width: 900px">
              {{ info.sourceid }}
            </span>
          </div>
          <div class="star">
            <div>抬头:</div>
            <el-input
              size="mini"
              v-model="info.invoice_header"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div class="star">
            <div>邮箱:</div>
            <el-input
              size="mini"
              v-model="info.email"
              :disabled="islook == 1"
            ></el-input>
          </div>
        </div>
        <div class="dialogOrderUpdate" v-if="info.invoice_headerid == 18661">
          <div style="width: 900px">
            <div>订单号:</div>
            <span style="color: #2c70d6; width: 900px">
              {{ info.sourceid }}
            </span>
          </div>
          <div class="star">
            <div>抬头:</div>
            <el-input
              size="mini"
              v-model="info.invoice_header"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div class="star">
            <div>邮箱:</div>
            <el-input
              size="mini"
              v-model="info.email"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div class="star">
            <div>税号:</div>
            <el-input
              size="mini"
              v-model="info.invoicing_number"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>开户行:</div>
            <el-input
              size="mini"
              v-model="info.opening_bank"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>开户行号:</div>
            <el-input
              size="mini"
              v-model="info.opening_bank_number"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>地址:</div>
            <el-input
              size="mini"
              v-model="info.opening_bank_address"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div>
            <div>电话:</div>
            <el-input
              size="mini"
              v-model="info.opening_bank_tel"
              :disabled="islook == 1"
            ></el-input>
          </div>
        </div>
        <div style="display: flex; align-items: center">
          客服备注:<el-input
            size="mini"
            style="width: 720px; margin-left: 10px; margin-top: 10px"
            v-model="info.notes"
            :disabled="islook == 1"
          ></el-input>
        </div>
      </div>
      <div style="margin-top: 10px">
        <div>子订单信息</div>
        <el-table border :data="info.order_detail" size="mini">
          <el-table-column
            label="子订单号"
            align="center"
            width="180"
            prop="son_order_no"
          >
          </el-table-column>
          <el-table-column label="商品标题" align="center" prop="product_name">
          </el-table-column>
          <el-table-column label="购买数量" align="center" prop="num">
          </el-table-column>
          <el-table-column
            label="子订单号实付金额"
            align="center"
            prop="pay_amount"
          >
            <template slot-scope="{ row }">
              <el-input
                v-model="row.pay_amount"
                placeholder=""
                size="mini"
                v-if="hongchong_status == 2"
              ></el-input>
              <div v-else>{{ row.pay_amount }}</div>
            </template>
          </el-table-column>
          <el-table-column label="货品编号" align="center" prop="sku_code">
          </el-table-column>
        </el-table>
        <div style="text-align: right; color: red; font-weight: 800">
          合计：{{ numt }}
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">取 消</el-button>
        <el-button type="primary" size="mini" @click="onUpdateChongHong"
          >确 认</el-button
        >
      </span>
    </el-dialog>
    <el-dialog :title="isD == 2?'发起冲红申请':isD == 1?'修改开票信息':isD == 3?'取消多合一开票': isD == 4? '再次申请开票': ''" :visible.sync="dialogVisibleupdateDD"
               :before-close="handleClose" width="900px">
      <div v-if="step == 1">
        <dialogDD :type="isD" @onMultipleSelectionD="onMultipleSelectionD" v-if="dialogVisibleupdateDD && step == 1"></dialogDD>
        <div slot="footer" class="dialog-footer" style="margin-top: 10px">
          <el-button @click="handleStepD" size="mini" v-if="isD != 3" :disabled="!multipleSelectionD" type="primary">下一步</el-button>
          <el-button @click="handleStepCancel" size="mini" type="primary" v-else :disabled="!multipleSelectionD">确定</el-button>
        </div>
      </div>
      <div v-else>
        <div v-if="isD == 2">
          <div>
            <el-radio v-model="hongchong_status" label="1"
              >只冲红不开票</el-radio
            >
            <el-radio v-model="hongchong_status" label="2">冲红再开票</el-radio>
          </div>
          <div class="dialogOrderUpdate" v-if="hongchong_status == 1">
            <div style="width: 900px; margin: 20px 0">
              <div style="text-align: left">订单号:</div>
              <span style="color: #2c70d6; width: 900px">
                {{ infoD.sourceidarr.join(",") }}
              </span>
            </div>
            <!-- <div>
              <div>店铺:</div>
              {{ infoD.sellerid | shopfilters() }}
            </div> -->
          </div>
          <div v-if="hongchong_status == 2" style="margin-top: 10px">
            <div>
              <el-radio-group
                v-model="infoD.invoice_headerid"
                style="margin: 10px 0"
                size="mini"
              >
                <el-radio label="900">个人电子发票</el-radio>
                <el-radio label="18661">公司电子发票</el-radio>
              </el-radio-group>
            </div>
            <div class="dialogOrderUpdate" v-if="infoD.invoice_headerid == 900">
              <div style="width: 900px">
                <div>订单号:</div>
                <span style="color: #2c70d6; width: 900px">
                  {{ infoD.sourceidarr.join(",") }}
                </span>
              </div>
              <div class="star">
                <div>抬头:</div>
                <el-input
                  size="mini"
                  v-model="infoD.invoice_header"
                  :disabled="islook == 1"
                ></el-input>
              </div>
              <div class="star">
                <div>邮箱:</div>
                <el-input
                  size="mini"
                  v-model="infoD.email"
                  :disabled="islook == 1"
                ></el-input>
              </div>
            </div>
            <div
              class="dialogOrderUpdate"
              v-if="infoD.invoice_headerid == 18661"
            >
              <div style="width: 900px">
                <div>订单号:</div>
                <span style="color: #2c70d6; width: 900px">
                  {{ infoD.sourceid }}
                </span>
              </div>
              <div class="star">
                <div>抬头:</div>
                <el-input
                  size="mini"
                  v-model="infoD.invoice_header"
                  :disabled="islook == 1"
                ></el-input>
              </div>
              <div class="star">
                <div>邮箱:</div>
                <el-input
                  size="mini"
                  v-model="infoD.email"
                  :disabled="islook == 1"
                ></el-input>
              </div>
              <div class="star">
                <div>税号:</div>
                <el-input
                  size="mini"
                  v-model="infoD.invoicing_number"
                  :disabled="islook == 1"
                ></el-input>
              </div>
              <div>
                <div>开户行:</div>
                <el-input
                  size="mini"
                  v-model="infoD.opening_bank"
                  :disabled="islook == 1"
                ></el-input>
              </div>
              <div>
                <div>开户行号:</div>
                <el-input
                  size="mini"
                  v-model="infoD.opening_bank_number"
                  :disabled="islook == 1"
                ></el-input>
              </div>
              <div>
                <div>地址:</div>
                <el-input
                  size="mini"
                  v-model="infoD.opening_bank_address"
                  :disabled="islook == 1"
                ></el-input>
              </div>
              <div>
                <div>电话:</div>
                <el-input
                  size="mini"
                  v-model="infoD.opening_bank_tel"
                  :disabled="islook == 1"
                ></el-input>
              </div>
            </div>
            <div style="display: flex; align-items: center">
              客服备注:<el-input
                size="mini"
                style="width: 720px; margin-left: 10px; margin-top: 10px"
                v-model="infoD.notes"
                :disabled="islook == 1"
              ></el-input>
            </div>
          </div>

          <div style="margin-top: 10px">
            <div>子订单信息</div>
            <el-table
              border
              :data="infoD.order_detail"
              size="mini"
              height="400"
            >
              <el-table-column
                label="子订单号"
                align="center"
                width="180"
                prop="son_order_no"
              >
              </el-table-column>
              <el-table-column
                label="商品标题"
                align="center"
                prop="product_name"
              >
              </el-table-column>
              <el-table-column label="购买数量" align="center" prop="num">
              </el-table-column>
              <el-table-column
                label="子订单号实付金额"
                align="center"
                prop="pay_amount"
              >
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.pay_amount"
                    placeholder=""
                    size="mini"
                    v-if="hongchong_status == 2"
                  ></el-input>
                  <div v-else>{{ row.pay_amount }}</div>
                </template>
              </el-table-column>
              <el-table-column label="货品编号" align="center" prop="sku_code">
              </el-table-column>
            </el-table>
            <div style="text-align: right; color: red; font-weight: 800">
              合计：{{ numD }}
            </div>
          </div>
        </div>
        <div v-if="isD == 1 || isD == 4">
          <div>
            <el-radio
              v-model="infoD.invoice_headerid"
              label="900"
              :disabled="islook == 1"
              >个人电子发票</el-radio
            >
            <el-radio
              v-model="infoD.invoice_headerid"
              label="18661"
              :disabled="islook == 1"
              >公司电子发票</el-radio
            >
          </div>
          <div class="dialogOrderUpdate" v-if="infoD.invoice_headerid == 900">
            <div style="width: 900px">
              <div>订单号:</div>
              <span style="color: #2c70d6; width: 900px">
                {{ infoD.sourceidarr.join(",") }}
              </span>
            </div>
            <div class="star">
              <div>抬头:</div>
              <el-input
                size="mini"
                v-model="infoD.invoice_header"
                :disabled="islook == 1"
              ></el-input>
            </div>
            <div class="star">
              <div>邮箱:</div>
              <el-input
                size="mini"
                v-model="infoD.email"
                :disabled="islook == 1"
              ></el-input>
            </div>
          </div>
          <div class="dialogOrderUpdate" v-if="infoD.invoice_headerid == 18661">
            <div style="width: 900px">
              <div>订单号:</div>
              <span style="color: #2c70d6; width: 900px">
                {{ infoD.sourceidarr.join(",") }}
              </span>
            </div>
            <div class="star">
              <div>抬头:</div>
              <el-input
                size="mini"
                v-model="infoD.invoice_header"
                :disabled="islook == 1"
              ></el-input>
            </div>
            <div class="star">
              <div>邮箱:</div>
              <el-input
                size="mini"
                v-model="infoD.email"
                :disabled="islook == 1"
              ></el-input>
            </div>
            <div class="star">
              <div>税号:</div>
              <el-input
                size="mini"
                v-model="infoD.invoicing_number"
                :disabled="islook == 1"
              ></el-input>
            </div>
            <div>
              <div>开户行:</div>
              <el-input
                size="mini"
                v-model="infoD.opening_bank"
                :disabled="islook == 1"
              ></el-input>
            </div>
            <div>
              <div>开户行号:</div>
              <el-input
                size="mini"
                v-model="infoD.opening_bank_number"
                :disabled="islook == 1"
              ></el-input>
            </div>
            <div>
              <div>地址:</div>
              <el-input
                size="mini"
                v-model="infoD.opening_bank_address"
                :disabled="islook == 1"
              ></el-input>
            </div>
            <div>
              <div>电话:</div>
              <el-input
                size="mini"
                v-model="infoD.opening_bank_tel"
                :disabled="islook == 1"
              ></el-input>
            </div>
          </div>
          <div style="display: flex; align-items: center">
            客服备注:<el-input
              size="mini"
              style="width: 720px; margin-left: 10px; margin-top: 10px"
              v-model="infoD.notes"
              :disabled="islook == 1"
            ></el-input>
          </div>
          <div style="margin-top: 10px">
            <div>开票商品</div>
            <el-table
              border
              :data="infoD.order_detail"
              size="mini"
              height="400"
            >
              <el-table-column
                label="子订单号"
                align="center"
                width="180"
                prop="son_order_no"
              >
              </el-table-column>
              <el-table-column
                label="商品标题"
                align="center"
                prop="product_name"
              >
              </el-table-column>
              <el-table-column label="购买数量" align="center" prop="num">
              </el-table-column>
              <el-table-column
                label="子订单号实付金额"
                align="center"
                prop="pay_amount"
              >
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.pay_amount"
                    placeholder=""
                    size="mini"
                    v-if="islook != 1"
                  ></el-input>
                  <div v-else>{{ row.pay_amount }}</div>
                </template>
              </el-table-column>
              <el-table-column label="货品编号" align="center" prop="sku_code">
              </el-table-column>
            </el-table>
            <div style="text-align: right; color: red; font-weight: 800">
              合计：{{ numD }}
            </div>
          </div>
        </div>

        <span slot="footer" class="dialog-footer" style="text-align: right">
          <el-button @click="handleClose" size="mini">取 消</el-button>
          <el-button
            type="primary"
            size="mini"
            @click="onUpdateInvoicingDD"
            v-if="islook != 1"
            >确 认</el-button
          >
        </span>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getStore } from "@/utils/localStorage.js";
import {
  postAdminBanNiuGetInvoiceList_all,
  postAdminBanNiuGetInvoiceShop,
  postAdminBanNiulookInvoicing,
  postAdminSetInvoiceDetail,
  postAdminsetrequestInvoicedetail,
  postAdminsetHongchong,
  postAdminrequestInvoicedetail,
  postAdmincancellationInvoicelist,
  postAdminlookHongchongdetail,
  postAdminBanNiugetInvoiceListBanniu,
} from "@/api";
import { floatAdd } from "@/utils/algorithm.js";
import pagination from "@/components/pagination.vue";
import dialogD from "./components/dialogD.vue";
import dialogDD from "./components/dialogDD.vue";
let that;
export default {
  components: { pagination, dialogD, dialogDD },
  async beforeCreate() {
    that = this;
  },
  computed: {
    numt() {
      let num = 0;
      if (this.info) {
        let order_detail = this.info.order_detail;

        if (order_detail.length) {
          for (let index = 0; index < order_detail.length; index++) {
            if (order_detail[index].pay_amount) {
              num = floatAdd(num, Number(order_detail[index].pay_amount));
            }
          }
        }
      }

      return num;
    },
    numD() {
      let num = 0;
      if (this.infoD) {
        let order_detail = this.infoD.order_detail;
        if (order_detail.length) {
          for (let index = 0; index < order_detail.length; index++) {
            if (order_detail[index].pay_amount) {
              num = floatAdd(num, Number(order_detail[index].pay_amount));
            }
          }
        }
      }
      return num;
    },
  },
  filters: {
    shopfilters(val) {
      if (val) {
        let shoplist = that.shoplist;
        let index = shoplist.map((item) => item.sellerid).indexOf(val);
        return shoplist[index].sellertitle || "";
      } else {
        return "";
      }
    },
  },
  data() {
    return {
      is: true,
      isD: 1,
      loading: false,
      dialogVisible: false,
      dialogVisibleupdate: false,
      dialogVisibleupdateC: false,
      dialogVisibleupdateD: false,
      dialogVisibleupdateDD: false,
      islook: "",
      info: "",
      infoD: "",
      step: 1,
      hongchong_status: "1",
      cities: [
        {
          label: "未开票",
          value: "0",
        },
        {
          label: "开票失败",
          value: "2",
        },
        {
          label: "已开票",
          value: "1",
        },
        {
          label: "申请冲红",
          value: "3",
        },
        {
          label: "已冲红",
          value: "4",
        },
        {
          label: "冲红失败",
          value: "5",
        },
      ],
      checkedCities: ["未开票", "开票失败"],
      shoplist: [],
      statuslist: [
        {
          label: "全部",
          value: "",
        },
        {
          label: "待处理",
          value: "0",
        },
        {
          label: "已完成",
          value: "1",
        },
        {
          label: "处理中",
          value: "2",
        },
        {
          label: "暂停中",
          value: "3",
        },
      ],
      form: {
        sellerid: "",
        sourceidarr: "",
        invoicing_statusarr: [],
        buyername: "",
        status: "",
        title: "",
        strdate: "",
        enddate: "",
        type: 1,
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
      row: "",
      multipleSelection: [],
      multipleSelectionD: "",
    };
  },

  async activated() {
    this.browserHeight =
      window.innerHeight ||
      document.documentElement.clientHeight ||
      document.body.clientHeight;
    // this.form.order_processor = getStore("userinfo").username;
    let form = this.form;
    await this.postAdminBanNiuGetInvoiceShop();
    await this.postAdminBanNiuGetInvoiceList_all(form);

    this.userinfo = getStore("userinfo");
  },
  //   updated() {
  //     this.$nextTick(() => {
  //       this.$refs.multipleTable.doLayout();
  //     });
  //   },
  methods: {
    async onUpdatelist() {
      let { form } = this;
      let res = await postAdminBanNiugetInvoiceListBanniu(form);
      // await this.onSearch();
    },
    onDetail(sourceid) {
      this.$router.push({
        name: "Kpdetail",
        query: {
          sourceid,
        },
      });
    },
    onMultipleSelection(val) {
      this.multipleSelection = val;
    },
    onMultipleSelectionD(val) {
      this.multipleSelectionD = val;
    },
    onMerge() {
      this.dialogVisibleupdateD = true;
    },
    onMergeDD(e) {
      this.isD = e;
      this.dialogVisibleupdateDD = true;
    },
    handleClose() {
      this.dialogVisibleupdate = false;
      this.dialogVisibleupdateD = false;
      this.dialogVisibleupdateDD = false;
      this.dialogVisibleupdateC = false;
      this.info = "";
      this.infoD = "";
      this.islook = "";
      this.step = 1;
      this.multipleSelectionD = "";
      this.multipleSelection = "";
    },
    async onUpdateChongHong() {
      let { hongchong_status, info } = this;
      let obj = {
        hongchong_status,
        sourceidarr: [info.sourceid],
      };
      if (hongchong_status == 2) {
        let order_detail = [];
        for (let index = 0; index < info.order_detail.length; index++) {
          let detail = info.order_detail[index];
          let obj = {
            id: detail.id,
            num: detail.num,
            pay_amount: detail.pay_amount || 0,
          };
          order_detail.push(obj);
        }
        if (
          info.invoice_headerid == "900" &&
          info.invoice_header &&
          info.email
        ) {
          obj = {
            hongchong_status,
            sourceidarr: [info.sourceid],
            invoice_headerid: info.invoice_headerid,
            invoice_header: info.invoice_header,
            email: info.email,
            notes: info.notes,
            order_detail: order_detail,
            pay_amount: this.numt,
          };
        } else if (
          info.invoice_headerid == "18661" &&
          info.invoicing_number &&
          info.invoice_header &&
          info.email
        ) {
          obj = {
            hongchong_status,
            sourceidarr: [info.sourceid],
            invoice_headerid: info.invoice_headerid,
            invoice_header: info.invoice_header,
            email: info.email,
            invoicing_number: info.invoicing_number,
            opening_bank: info.opening_bank,
            opening_bank_number: info.opening_bank_number,
            opening_bank_tel: info.opening_bank_tel,
            opening_bank_address: info.opening_bank_address,
            notes: info.notes,
            order_detail: order_detail,
            pay_amount: this.numt,
          };
        } else {
          this.$message.warning("必填项不能为空");
          return;
        }
      }
      let res = await postAdminsetHongchong(obj);
      this.$message.success(res.msg);
      await this.postAdminBanNiuGetInvoiceList_all(this.form);
      this.handleClose();
      this.info = "";
    },
    onChongHong(row) {
      this.info = JSON.parse(JSON.stringify(row));

      this.dialogVisibleupdateC = true;
    },
    async handleStepCancel() {
      let { multipleSelectionD } = this;
      let res = await postAdmincancellationInvoicelist({
        merge_tagarr: multipleSelectionD,
      });
      this.$message.success(res.msg);
      await this.postAdminBanNiuGetInvoiceList_all(this.form);
      this.handleClose();
    },
    async onChangeCheckboxGroup() {
      await this.postAdminBanNiuGetInvoiceList_all(this.form);
    },
    async handleStepD() {
      let { multipleSelectionD, isD } = this;
      console.log("multipleSelectionD", multipleSelectionD);
      let sourceidarr = [];
      let multipleSelection = multipleSelectionD.list;
      for (let index = 0; index < multipleSelection.length; index++) {
        sourceidarr.push(multipleSelection[index].sourceid);
      }
      let res = await postAdminrequestInvoicedetail({
        sourceidarr,
      });
      console.log("res", res);
      let data = res.data;
      if (isD == 3) {
        if (!data.invoice_headerid) {
          data.invoice_headerid = 900;
        }
      }
      let info = data;
      this.step = 2;
      this.infoD = info;
    },
    handleStep() {
      let { multipleSelection } = this;
      console.log("multipleSelection", multipleSelection);
      let info = {
        sourceidarr: [],
        order_detail: [],
        invoice_headerid: "900",
        invoice_header: "",
        email: "",
        invoicing_number: "",
        opening_bank: "",
        opening_bank_number: "",
        opening_bank_address: "",
        opening_bank_tel: "",
        notes: "",
      };
      for (let index = 0; index < multipleSelection.length; index++) {
        info.sourceidarr.push(multipleSelection[index].sourceid);
        info.order_detail.push(...multipleSelection[index].order_detail);
      }

      this.step = 2;
      this.infoD = info;
    },
    async onUpdateInvoicingDD() {
      let { infoD, isD } = this;
      if (isD == 2) {
        let info = infoD;
        let { hongchong_status } = this;
        let obj = {
          hongchong_status,
          sourceidarr: info.sourceidarr,
        };
        if (hongchong_status == 2) {
          let order_detail = [];
          for (let index = 0; index < info.order_detail.length; index++) {
            let detail = info.order_detail[index];
            let obj = {
              id: detail.id,
              num: detail.num,
              pay_amount: detail.pay_amount || 0,
            };
            order_detail.push(obj);
          }
          if (
            info.invoice_headerid == "900" &&
            info.invoice_header &&
            info.email
          ) {
            obj = {
              hongchong_status,
              sourceidarr: info.sourceidarr,
              invoice_headerid: info.invoice_headerid,
              invoice_header: info.invoice_header,
              email: info.email,
              notes: info.notes,
              order_detail: order_detail,
              pay_amount: this.numD,
            };
          } else if (
            info.invoice_headerid == "18661" &&
            info.invoicing_number &&
            info.invoice_header &&
            info.email
          ) {
            obj = {
              hongchong_status,
              sourceidarr: info.sourceidarr,
              invoice_headerid: info.invoice_headerid,
              invoice_header: info.invoice_header,
              email: info.email,
              invoicing_number: info.invoicing_number,
              opening_bank: info.opening_bank,
              opening_bank_number: info.opening_bank_number,
              opening_bank_tel: info.opening_bank_tel,
              opening_bank_address: info.opening_bank_address,
              notes: info.notes,
              order_detail: order_detail,
              pay_amount: this.numD,
            };
          } else {
            this.$message.warning("必填项不能为空");
            return;
          }
        }
        let res = await postAdminsetHongchong(obj);
        this.$message.success(res.msg);
        await this.postAdminBanNiuGetInvoiceList_all(this.form);
        this.handleClose();
        this.infoD = "";
        this.step = 1;
      }
      if (isD == 1) {
        let info = infoD;
        let order_detail = [];
        for (let index = 0; index < info.order_detail.length; index++) {
          let detail = info.order_detail[index];
          let obj = {
            id: detail.id,
            num: detail.num,
            pay_amount: detail.pay_amount || 0,
          };
          order_detail.push(obj);
        }
        let type = 2;
        if (
          info.invoice_headerid == "900" &&
          info.invoice_header &&
          info.email
        ) {
          let obj = {
            sourceidarr: info.sourceidarr,
            type,
            invoice_headerid: info.invoice_headerid,
            invoice_header: info.invoice_header,
            email: info.email,
            notes: info.notes,
            order_detail: order_detail,
            pay_amount: this.numD,
          };
          let res = await postAdminsetrequestInvoicedetail(obj);
          console.log("res---->", res);
          this.$message.success(res.msg);
          await this.postAdminBanNiuGetInvoiceList_all(this.form);
          this.handleClose();
          this.infoD = "";
          this.step = 1;
        } else if (
          info.invoice_headerid == "18661" &&
          info.invoicing_number &&
          info.invoice_header &&
          info.email
        ) {
          let obj = {
            sourceidarr: info.sourceidarr,
            type,
            invoice_headerid: info.invoice_headerid,
            invoice_header: info.invoice_header,
            email: info.email,
            invoicing_number: info.invoicing_number,
            opening_bank: info.opening_bank,
            opening_bank_number: info.opening_bank_number,
            opening_bank_tel: info.opening_bank_tel,
            opening_bank_address: info.opening_bank_address,
            notes: info.notes,
            order_detail: order_detail,
            pay_amount: this.numD,
          };
          let res = await postAdminsetrequestInvoicedetail(obj);
          console.log("res---->", res);
          this.$message.success(res.msg);
          await this.postAdminBanNiuGetInvoiceList_all(this.form);
          this.handleClose();
          this.infoD = "";
          this.step = 1;
        } else {
          this.$message.warning("必填项不能为空");
        }
      }
      if (isD == 4) {
        let info = infoD;
        let order_detail = [];
        for (let index = 0; index < info.order_detail.length; index++) {
          let detail = info.order_detail[index];
          let obj = {
            id: detail.id,
            num: detail.num,
            pay_amount: detail.pay_amount || 0,
          };
          order_detail.push(obj);
        }
        let type = 1;
        if (
          info.invoice_headerid == "900" &&
          info.invoice_header &&
          info.email
        ) {
          let obj = {
            sourceidarr: info.sourceidarr,
            type,
            invoice_headerid: info.invoice_headerid,
            invoice_header: info.invoice_header,
            email: info.email,
            notes: info.notes,
            order_detail: order_detail,
            pay_amount: this.numt,
          };
          let res = await postAdminSetInvoiceDetail(obj);
          this.$message.success(res.msg);
          await this.postAdminBanNiuGetInvoiceList_all(this.form);
          this.handleClose();
          this.infoD = "";
          this.step = 1;
        } else if (
          info.invoice_headerid == "18661" &&
          info.invoicing_number &&
          info.invoicing_number
        ) {
          let obj = {
            sourceidarr: [info.sourceid],
            type,
            invoice_headerid: info.invoice_headerid,
            invoice_header: info.invoice_header,
            email: info.email,
            invoicing_number: info.invoicing_number,
            opening_bank: info.opening_bank,
            opening_bank_number: info.opening_bank_number,
            opening_bank_tel: info.opening_bank_tel,
            opening_bank_address: info.opening_bank_address,
            notes: info.notes,
            order_detail: order_detail,
            pay_amount: this.numt,
          };
          let res = await postAdminSetInvoiceDetail(obj);
          this.$message.success(res.msg);
          await this.postAdminBanNiuGetInvoiceList_all(this.form);
          this.handleClose();
          this.infoD = "";
          this.step = 1;
        } else {
          this.$message.warning("必填项不能为空");
        }
      }
    },
    async onUpdateInvoicingD() {
      let { infoD, islook } = this;
      let info = infoD;
      let order_detail = [];
      for (let index = 0; index < info.order_detail.length; index++) {
        let detail = info.order_detail[index];
        let obj = {
          id: detail.id,
          num: detail.num,
          pay_amount: detail.pay_amount || 0,
        };
        order_detail.push(obj);
      }
      let type = 1;
      if (info.invoice_headerid == "900" && info.invoice_header && info.email) {
        let obj = {
          sourceidarr: info.sourceidarr,
          type,
          invoice_headerid: info.invoice_headerid,
          invoice_header: info.invoice_header,
          email: info.email,
          notes: info.notes,
          order_detail: order_detail,
          pay_amount: this.numD,
        };
        let res = await postAdminsetrequestInvoicedetail(obj);
        console.log("res---->", res);
        this.$message.success(res.msg);
        await this.postAdminBanNiuGetInvoiceList_all(this.form);
        this.handleClose();
        this.infoD = "";
        this.step = 1;
      } else if (
        info.invoice_headerid == "18661" &&
        info.invoicing_number &&
        info.invoicing_number
      ) {
        let obj = {
          sourceidarr: info.sourceidarr,
          type,
          invoice_headerid: info.invoice_headerid,
          invoice_header: info.invoice_header,
          email: info.email,
          invoicing_number: info.invoicing_number,
          opening_bank: info.opening_bank,
          opening_bank_number: info.opening_bank_number,
          opening_bank_tel: info.opening_bank_tel,
          opening_bank_address: info.opening_bank_address,
          notes: info.notes,
          order_detail: order_detail,
          pay_amount: this.numD,
        };
        let res = await postAdminsetrequestInvoicedetail(obj);
        console.log("res---->", res);
        this.$message.success(res.msg);
        await this.postAdminBanNiuGetInvoiceList_all(this.form);
        this.handleClose();
        this.infoD = "";
        this.step = 1;
      } else {
        this.$message.warning("必填项不能为空");
      }
    },
    async onUpdateInvoicing() {
      let { info, islook } = this;
      let order_detail = [];
      for (let index = 0; index < info.order_detail.length; index++) {
        let detail = info.order_detail[index];
        let obj = {
          id: detail.id,
          num: detail.num,
          pay_amount: detail.pay_amount || 0,
        };
        order_detail.push(obj);
      }
      let type = islook == 2 ? 0 : 1;
      if (info.invoice_headerid == "900" && info.invoice_header && info.email) {
        let obj = {
          sourceidarr: [info.sourceid],
          type,
          invoice_headerid: info.invoice_headerid,
          invoice_header: info.invoice_header,
          email: info.email,
          notes: info.notes,
          order_detail: order_detail,
          pay_amount: this.numt,
        };
        let res = await postAdminSetInvoiceDetail(obj);
        console.log("res---->", res);
        this.$message.success(res.msg);
        await this.postAdminBanNiuGetInvoiceList_all(this.form);
        this.handleClose();
        this.info = "";
      } else if (
        info.invoice_headerid == "18661" &&
        info.invoicing_number &&
        info.invoicing_number
      ) {
        let obj = {
          sourceidarr: [info.sourceid],
          type,
          invoice_headerid: info.invoice_headerid,
          invoice_header: info.invoice_header,
          email: info.email,
          invoicing_number: info.invoicing_number,
          opening_bank: info.opening_bank,
          opening_bank_number: info.opening_bank_number,
          opening_bank_tel: info.opening_bank_tel,
          opening_bank_address: info.opening_bank_address,
          notes: info.notes,
          order_detail: order_detail,
          pay_amount: this.numt,
        };
        let res = await postAdminSetInvoiceDetail(obj);
        console.log("res---->", res);
        this.$message.success(res.msg);
        await this.postAdminBanNiuGetInvoiceList_all(this.form);
        this.handleClose();
        this.info = "";
      } else {
        this.$message.warning("必填项不能为空");
      }
    },
    // 打开修改信息弹窗
    async onUpdateinfo(row, type) {
      if (type == 1) {
        let obj = {
          sourceidarr: row.sourceid,
        };
        let res = await postAdminlookHongchongdetail(obj);
        this.info = res.data;
      } else {
        if (!row.invoice_headerid) {
          row.invoice_headerid = 900;
        }
        this.info = row;
      }
      this.islook = type;
      this.dialogVisibleupdate = true;
    },
    // 店铺列表
    async postAdminBanNiuGetInvoiceShop() {
      let res = await postAdminBanNiuGetInvoiceShop();
      console.log("店铺名字---》", res);
      this.shoplist = res.data;
    },
    // 下载发票
    async downloadInvoice(number) {
      let res = await postAdminBanNiulookInvoicing({ number });
      window.open(res.data.c_url);
      console.log("下载发票", res);
    },
    // 列表
    async postAdminBanNiuGetInvoiceList_all(obj) {
      this.loading = true;
      this.form = obj;
      let data = JSON.parse(JSON.stringify(obj));
      let date = data.strdate;
      if (date) {
          if (Array.isArray(date)) {
              data.strdate = date[0];
              data.enddate = date[1];
          }
      } else {
          this.form.strdate = "";
          this.form.enddate = "";
      }
      let sourceidarr = data.sourceidarr;
      if (sourceidarr) {
        data.sourceidarr = sourceidarr.split(",");
      } else {
        data.sourceidarr = [];
      }
      postAdminBanNiuGetInvoiceList_all(data)
        .then((res) => {
          this.loading = false;
          let data = res.data;
          this.tableData = data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    async onChange() {
      this.is = false;
      await this.postAdminBanNiuGetInvoiceList_all(this.form);
      this.is = true;
    },
    // 搜索
    onSearch() {
      this.form.page = 1;

      this.postAdminBanNiuGetInvoiceList_all(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;

  > div {
    display: flex;
  }

  &-item {
    margin-right: 10px;
  }
}

.dialogOrderUpdate {
  display: flex;
  flex-wrap: wrap;

  > div {
    width: 420px;
    display: flex;
    align-items: center;
    margin-top: 10px;

    > div {
      width: 60px;
      text-align: right;
      margin-right: 10px;
    }

    > .el-input {
      width: 320px;
    }
  }
}

.dialogimgdiv {
  display: flex;
  justify-content: center;

  > div {
    margin-right: 10px;
  }
}

.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
